<template>
  <div v-show="$route.name == 'product-order'">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>肉码出仓订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <div style="margin-bottom: 20px;">肉码出仓订单列表</div>
      <el-table
        border
        v-loading="loading"
        :data="applyData"
        style="margin-top: 10px;">
        <el-table-column label="采购单号" prop="sell_number" min-width="120" align="center" fixed="left"></el-table-column>
        <el-table-column label="采购日期" prop="purchase_time" min-width="110" align="center" fixed="left">
          <template slot-scope="scope">
            <span>{{ new Date(scope.row.purchase_time).toLocaleDateString().split('/').join('-') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="来源" prop="basename" min-width="120" align="center"></el-table-column>
        <el-table-column label="操作" width="80" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" type="success" @click="print(scope.row.id)">打印</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pager.currPage"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="pager.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pager.totalCount">
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      base: 0,
      pager: {
        currPage: 1,
        pageSize: 10,
        totalCount: 0
      },
      applyData: []
    }
  },
  mounted() {
    this.getUserInfo()
    this.getInnerList()
  },
  methods: {
    // 获取用户信息
    async getUserInfo() {
      const { data: result } = await this.$http.get('/user/' + localStorage.userid)
      if (result.status !== 200) return this.$message.error(result.msg)
      this.base = result.data.base ? result.data.base * 1 : 0
    },
    async getInnerList() {
      this.loading = true
      const params = {
        page: this.pager.currPage,
        pageSize: this.pager.pageSize,
        process: 1,
        houseSell: 1
      }
      const { data: result } = await this.$http.get('/house-out/order', { params: params })
      if (result.status !== 200) {
        this.loading = false
        this.applyData = '暂无数据'
        return this.$message.error(result.msg)
      }
      this.loading = false
      this.applyData = result.data
      this.pager = result.pager
    },
    // 打印
    print(id) {
      this.$router.push({
        name: 'print',
        params: { id: id }
      })
    },
    handleSizeChange(pageSize) {
      this.pager.pageSize = pageSize
      this.getInnerList()
    },
    handleCurrentChange(currentPage) {
      this.pager.currPage = currentPage
      this.getInnerList()
    }
  }
}
</script>